//
//  DeliveryViewController.m
//  YYPHSpeedJump
//
//  Created by speedjump on 16/1/3.
//  Copyright © 2016年 sujiang. All rights reserved.
//

#import "DeliveryViewController.h"

@interface DeliveryViewController ()<UIScrollViewDelegate, UIAlertViewDelegate>

@end

@implementation DeliveryViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"查看物流";
    [self addSubViews];
    self.view.backgroundColor = [UIColor whiteColor];
}

- (void)addSubViews
{
    [self.goodImage sd_setImageWithURL:[NSURL URLWithString:self.model.head_img_url] placeholderImage:[UIImage imageNamed:@"tu-xiao"]];
    self.titleLb.text = self.model.name;
    self.priceLb.text = [NSString stringWithFormat:@"￥%@", self.model.buy_price];
    self.realName.text = [NSString stringWithFormat:@"收货人:%@", self.model.real_name];
    self.phone.text = [NSString stringWithFormat:@"联系电话:%@", self.model.phone];
    self.addressLb.text = self.model.address;
    self.waybillLabel.text = [NSString stringWithFormat:@"运单号:%@",self.model.express_order];
    if (self.model.status.integerValue == 3) {
        [self.ensure setTitle:@"提醒发货" forState:(UIControlStateNormal)];
        self.beginSend.backgroundColor = kColors(218, 166, 46, 1);
    } else if(self.model.status.integerValue == 4){
        [self.ensure setTitle:@"确认收货" forState:(UIControlStateNormal)];
        self.beginSend.backgroundColor = kColors(218, 166, 46, 1);
        self.sending.backgroundColor = kColors(218, 166, 46, 1);
    } else if(self.model.status.integerValue == 5) {
        [self.ensure setTitle:@"确认收货" forState:UIControlStateNormal];
        self.beginSend.backgroundColor = kColors(218, 166, 46, 1);
        self.sending.backgroundColor = kColors(218, 166, 46, 1);
        self.recive.backgroundColor = kColors(218, 166, 46, 1);
    }
    
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://m.kuaidi100.com/index_all.html?type=%@&postid=%@", self.model.express, self.model.express_order]]];
    NSLog(@"%@", self.model.express_order);
    [self.web loadRequest:request];
    self.web.backgroundColor = kColors(231, 231, 231, 1);
    self.web.scalesPageToFit = YES;
    self.web.scrollView.delegate = self;
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGPoint point = scrollView.contentOffset;
    if (point.x > 0) {
        scrollView.contentOffset = CGPointMake(0, point.y);
    }
}




// 申请退款
//- (IBAction)returnMoney:(id)sender {
//    
//    
//}

- (IBAction)enSure:(id)sender {
    if (self.model.status.integerValue == 3)
    {
        [Tools showAlert:@"已提醒!"];
        return;
    }
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"确认收到货了?" delegate:self cancelButtonTitle:@"是" otherButtonTitles:@"否", nil];
    [alert show];
    
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0) {
        NSString *string = [NSString stringWithFormat:@"%@%@", kBaseUrl, @"/user.do?cmd=ensure_get"];
        NSDictionary *dict = @{@"u":[[NSUserDefaults standardUserDefaults] objectForKey:@"user_id"], @"deal_id":self.model.deal_id};
        [NetworkHandle getInfoWithUrl:string dictionary:dict success:^(NSDictionary *dictionary) {
        }];
    }
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
